<?php

namespace App\Http\Controllers\Api\User;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\UserSetting;
use App\Http\Requests\Api\ApiRequest;

class SettingController extends Controller
{
   

    public function show(ApiRequest $request)
    {
        $rs['status'] = false;
        $where['user_id'] = $request->user_id; 
        $data = UserSetting::where($where)->first();
        if($data) {
            $rs['status'] = true;
            $rs['data'] = $data;
            return response()->json($rs);     
        }
        return response()->json($rs);       
    }

    public function save(ApiRequest $request)
    {
        $rs['status'] = false;
        $where['user_id'] = $request->user_id;
        $data = $request->pure();
       // dd($data);
        $flag = UserSetting::updateOrCreate($where,$data);;
        if($flag) {
            $rs['status'] = true;            
            return response()->json($rs);
        }
        return response()->json($rs);
    }
}
